<template>
  <div class="content">
    <!--结果-->
    <div class="result">
      <span class="large">{{fen}}</span>分
      <p>答题时间：{{examTime}} / 错题数：{{cuo}}</p>
      <div class="again" @click="toIndex()">
        返回首页
      </div>
      <div class="box"></div>
      <a class="again" :href="picurl" download="考试证书.jpg">
        下载证书
      </a>
    </div>
    <!---->
    <div  class="content">
      <!--导航条-->
      <div class="tag">
        <div class="tag_zhong">
          <div @click="style(1)" v-bind:class="style1">
            错题
          </div>
          <div @click="style(2)" v-bind:class="style2">
            标记题
          </div>
        </div>
      </div>
      <!--全部题-->
      <div v-if="show==1" class="answer_three">
        <div class="answer_three_header">
          共 {{radio.length+check.length+judge.length+fill.length}} 道题 <span>(其中单选题{{radio.length}}道，多选题{{check.length}}道，判断题{{judge.length}}道，填空题{{fill.length}}道)</span>
        </div>

        <!--单选题-->
        <div class="topic_ceshi">
          <div class="answer_three_tips">
            <span class="zi_lan">单选题</span>
          </div>
          <div v-for="(radios, index) in radio" class="tkj">
            <div class="subject">
              {{index+1}}. {{radios.content}}
            </div>
            <ul>
              <li v-for="radioss in radios.option">
                {{radioss}}
              </li>
              <li>
                正确答案：<span style="color: #3B50A1">{{radios.correctAnswer}}</span>          </li>
            </ul>

          </div>
        </div>
        <!--多选题-->
        <div class="topic_ceshi">
          <div class="answer_three_tips">
            <span class="zi_lan">多选题</span>
          </div>
          <div v-for="(checks, index) in check" class="tkj">
            <div class="subject">
              {{radio.length+(index+1) }}. {{checks.content}}
            </div>
            <ul>
              <li v-for="checkss in checks.option">
                {{checkss}}
              </li>
              <li>
                正确答案：<span style="color: #3B50A1">{{checks.correctAnswer}}</span>          </li>
            </ul>

          </div>
        </div>
        <!--判断题-->
        <div class="topic_ceshi">
          <div class="answer_three_tips">
            <span class="zi_lan">判断题</span>
          </div>
          <div v-for="(judges, index) in judge" class="tkj">
            <div class="subject">
              {{(check.length+radio.length)+(index+1) }}. {{judges.content}}
            </div>
            <ul>
              <li v-for="judgess in judges.option">
                {{judgess}}
              </li>
              <li>正确答案：<span style="color: #3B50A1">{{judges.correctAnswer}}</span>          </li>
            </ul>

          </div>
        </div>
        <!--填空题-->
        <div class="topic_ceshi">
          <div class="answer_three_tips">
            <span class="zi_lan">填空题</span>
          </div>
          <div v-for="(filles, index) in fill" class="tkj">
            <div class="subject">
              {{(check.length+radio.length+judge.length)+(index+1) }}. {{filles.content}}
            </div>
            <ul>
              <li>正确答案：<span style="color: #3B50A1">{{filles.correctAnswer}}</span>          </li>
            </ul>

          </div>
        </div>


      </div>
      <!--标记题-->
      <div v-if="show==2" class="answer_three">
        <div class="answer_three_header">
          共 {{markRadio.length+checkRadio.length+judgeRadio.length+fillRadio.length}} 道题 <span>(其中单选题{{markRadio.length}}道，多选题{{checkRadio.length}}道，判断题{{judgeRadio.length}}道，填空题{{fillRadio.length}}道)</span>
        </div>

        <!--单选题-->
        <div class="topic_ceshi">
          <div class="answer_three_tips">
            <span class="zi_lan">单选题</span>
          </div>
          <div v-for="(radios, index) in markRadio" class="tkj">
            <div class="subject">
              {{index+1}}. {{radios.content}}
            </div>
            <ul>
              <li v-for="radioss in radios.option">
                {{radioss}}
              </li>
              <li>正确答案：<span style="color: #3B50A1">{{radios.correctAnswer}}</span>          </li>
            </ul>

          </div>
        </div>
        <!--多选题-->
        <div class="topic_ceshi">
          <div class="answer_three_tips">
            <span class="zi_lan">多选题</span>
          </div>
          <div v-for="(checks, index) in checkRadio" class="tkj">
            <div class="subject">
              {{radio.length+(index+1) }}. {{checks.content}}
            </div>
            <ul>
              <li v-for="checkss in checks.option">
                {{checkss}}
              </li>
              <li>正确答案：<span style="color: #3B50A1">{{checks.correctAnswer}}</span>          </li>
            </ul>

          </div>
        </div>
        <!--判断题-->
        <div class="topic_ceshi">
          <div class="answer_three_tips">
            <span class="zi_lan">判断题</span>
          </div>
          <div v-for="(judges, index) in judgeRadio" class="tkj">
            <div class="subject">
              {{(check.length+radio.length)+(index+1) }}. {{judges.content}}
            </div>
            <ul>
              <li v-for="judgess in judges.option">
                {{judgess}}
              </li>
              <li>正确答案：<span style="color: #3B50A1">{{judges.correctAnswer}}</span>          </li>
            </ul>

          </div>
        </div>
        <!--填空题-->
        <div class="topic_ceshi">
          <div class="answer_three_tips">
            <span class="zi_lan">填空题</span>
          </div>
          <div v-for="(fills, index) in fillRadio" class="tkj">
            <div class="subject">
              {{(check.length+radio.length+judge.length)+(index+1) }}. {{fills.content}}
            </div>
            <ul>

              <li>正确答案：<span style="color: #3B50A1">{{fills.correctAnswer}}</span>          </li>
            </ul>

          </div>
        </div>


      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: '',
    data() {
      return {
        style1:'click',
        style2:'',

        radio:[],//单选题
        check:[],//多选题
        judge:[],//判断题
        fill:[],//填空题

        markRadio:[], //标记单选题
        checkRadio:[], //标记多选题
        judgeRadio:[], //标记判断题
        fillRadio:[],//标记填空题

        show:1,
        fen:'',
        examTime:'',//时间
        cuo:'',
        picurl:'',

      }
    },
    methods: {

      style(e){//调节标题样式
        if(e==1){
          this.show=1;
          this.style1='click';
          this.style2='';
          this.style3='';
          this.style4='';
        }
        if(e==2){
          this.show=2;
          this.style1='';
          this.style2='click';
          this.style3='';
          this.style4='';
        }

      },
      toIndex(){
        this.$router.push({  //核心语句
          path:'/index',   //跳转的路径
          query:{           //路由传参时push和query搭配使用 ，作用时传递参数
          }
        })
      },
      // 获取证书下载路径
      getExamCard(){
          var id=this.$route.query.examDetailId;
          this.$axios({
              url:'web/downExamCard/'+id,
              method:'GET',
              responseType: "arraybuffer", //指定返回数据的格式
          }).then(res => {
              return 'data:image/png;base64,' + btoa(
                  new Uint8Array(res.data)
                  .reduce((data, byte) => data + String.fromCharCode(byte), '')
              ); //文件流转换
          }).then(data => {
              if(!data){
                  this.$Message.error('暂无考试证书')
              }else {
                  this.picurl =data; //给图片赋值
              }
          })
      },
      ajjax(){
        var examDetailId= this.$route.query.examDetailId//结果id
        console.log(examDetailId)
        this.$axios({
          url: 'web/exam/grade/'+examDetailId,
          method: 'GET',
          data:{
          },
          headers: {
            'Content-Type': 'application/json;charset=UTF-8'
          },
          transformRequest: [function(data) {  //json
            data = JSON.stringify(data);
            return data
          }],
        }).then((response) => {
          console.log(response.data);
          if(response.data.code==500){
            this.$Message.error('获取失败！');
          }else {
            this.fen = response.data.grade;
            this.examTime = parseInt(response.data.examTime / 60) + '分' + parseInt(response.data.examTime % 60) + '秒';
            this.cuo = response.data.wrongOfNumbers;
//----------------------------错题
            for(var i=0;i<response.data.wrongQuestions.length;i++) {
//              渲染错题单选题
              if(response.data.wrongQuestions[i].type==1){
                var strArr=[];
                if(response.data.wrongQuestions[i].optionA==''||response.data.wrongQuestions[i].optionA==null){

                }else{strArr.push("A、"+response.data.wrongQuestions[i].optionA)}
                if(response.data.wrongQuestions[i].optionB==''||response.data.wrongQuestions[i].optionB==null){

                }else{strArr.push("B、"+response.data.wrongQuestions[i].optionB)}
                if(response.data.wrongQuestions[i].optionC==''||response.data.wrongQuestions[i].optionC==null){

                }else{strArr.push("C、"+response.data.wrongQuestions[i].optionC)}
                if(response.data.wrongQuestions[i].optionD==''||response.data.wrongQuestions[i].optionD==null){

                }else{strArr.push("D、"+response.data.wrongQuestions[i].optionD)}
                if(response.data.wrongQuestions[i].optionE==''||response.data.wrongQuestions[i].optionE==null){

                }else{strArr.push("E、"+response.data.wrongQuestions[i].optionE)}

                this.radio.push({
                  content:response.data.wrongQuestions[i].content,//题名
            correctAnswer: response.data.wrongQuestions[i].correctAnswer,//正确答案
                  id:response.data.wrongQuestions[i].id,//题目id
                  option: strArr,//题选项
                  questionType:response.data.wrongQuestions[i].questionType,//题型
                  userAnswer: response.data.wrongQuestions[i].userAnswers,//用户答案
                })
              }
//              渲染错题多选题
              if(response.data.wrongQuestions[i].type==2){
                var strArr=[];
                if(response.data.wrongQuestions[i].optionA==''||response.data.wrongQuestions[i].optionA==null){

                }else{strArr.push("A、"+response.data.wrongQuestions[i].optionA)}
                if(response.data.wrongQuestions[i].optionB==''||response.data.wrongQuestions[i].optionB==null){

                }else{strArr.push("B、"+response.data.wrongQuestions[i].optionB)}
                if(response.data.wrongQuestions[i].optionC==''||response.data.wrongQuestions[i].optionC==null){

                }else{strArr.push("C、"+response.data.wrongQuestions[i].optionC)}
                if(response.data.wrongQuestions[i].optionD==''||response.data.wrongQuestions[i].optionD==null){

                }else{strArr.push("D、"+response.data.wrongQuestions[i].optionD)}
                if(response.data.wrongQuestions[i].optionE==''||response.data.wrongQuestions[i].optionE==null){

                }else{strArr.push("E、"+response.data.wrongQuestions[i].optionE)}

                this.check.push({
                  content:response.data.wrongQuestions[i].content,//题名
            correctAnswer: response.data.wrongQuestions[i].correctAnswer,//正确答案
                  id:response.data.wrongQuestions[i].id,//题目id
                  option: strArr,//题选项
                  questionType:response.data.wrongQuestions[i].questionType,//题型
                  userAnswer: response.data.wrongQuestions[i].userAnswers,//用户答案
                })
              }
//              渲染错题判断题
              if(response.data.wrongQuestions[i].type==3){
                var strArr=[];
                if(response.data.wrongQuestions[i].optionA==''||response.data.wrongQuestions[i].optionA==null){

                }else{strArr.push("A、"+response.data.wrongQuestions[i].optionA)}
                if(response.data.wrongQuestions[i].optionB==''||response.data.wrongQuestions[i].optionB==null){

                }else{strArr.push("B、"+response.data.wrongQuestions[i].optionB)}
                if(response.data.wrongQuestions[i].optionC==''||response.data.wrongQuestions[i].optionC==null){

                }else{strArr.push("C、"+response.data.wrongQuestions[i].optionC)}
                if(response.data.wrongQuestions[i].optionD==''||response.data.wrongQuestions[i].optionD==null){

                }else{strArr.push("D、"+response.data.wrongQuestions[i].optionD)}
                if(response.data.wrongQuestions[i].optionE==''||response.data.wrongQuestions[i].optionE==null){

                }else{strArr.push("E、"+response.data.wrongQuestions[i].optionE)}

                this.judge.push({
                  content:response.data.wrongQuestions[i].content,//题名
            correctAnswer: response.data.wrongQuestions[i].correctAnswer,//正确答案
                  id:response.data.wrongQuestions[i].id,//题目id
                  option: strArr,//题选项
                  questionType:response.data.wrongQuestions[i].questionType,//题型
                  userAnswer: response.data.wrongQuestions[i].userAnswers,//用户答案
                })
              }
              if(response.data.wrongQuestions[i].type==5){
                this.fill.push({
                  content:response.data.wrongQuestions[i].content,//题名
                  correctAnswer: response.data.wrongQuestions[i].correctAnswer,//正确答案
                  id:response.data.wrongQuestions[i].id,//题目id
                  questionType:response.data.wrongQuestions[i].questionType,//题型
                  userAnswer: response.data.wrongQuestions[i].userAnswers,//用户答案
                })
              }
              }


            }
// --------------------------标记
//              渲染标记单选题
            for(var i=0;i<response.data.markQuestions.length;i++) {
              if (response.data.markQuestions[i].type == 1) {
                var strArr = [];
                if (response.data.markQuestions[i].optionA == '' || response.data.markQuestions[i].optionA == null) {
                } else {
                  strArr.push("A、"+response.data.markQuestions[i].optionA)
                }
                if (response.data.markQuestions[i].optionB == '' || response.data.markQuestions[i].optionB == null) {
                } else {
                  strArr.push("B、"+response.data.markQuestions[i].optionB)
                }
                if (response.data.markQuestions[i].optionC == '' || response.data.markQuestions[i].optionC == null) {
                } else {
                  strArr.push("C、"+response.data.markQuestions[i].optionC)
                }
                if (response.data.markQuestions[i].optionD == '' || response.data.markQuestions[i].optionD == null) {
                } else {
                  strArr.push("D、"+response.data.markQuestions[i].optionD)
                }
                if (response.data.markQuestions[i].optionE == '' || response.data.markQuestions[i].optionE == null) {
                } else {
                  strArr.push("E、"+response.data.markQuestions[i].optionE)
                }

                this.markRadio.push({
                  content: response.data.markQuestions[i].content,//题名
            correctAnswer: response.data.markQuestions[i].correctAnswer,//正确答案
                  id: response.data.markQuestions[i].id,//题目id
                  option: strArr,//题选项
                  questionType: response.data.markQuestions[i].questionType,//题型
                  userAnswer: response.data.markQuestions[i].userAnswers,//用户答案
                })
                console.log(this.markRadio)
              }
//              渲染标记多选题
              if (response.data.markQuestions[i].type == 2) {
                var strArr = [];
                if (response.data.markQuestions[i].optionA == '' || response.data.markQuestions[i].optionA == null) {
                } else {
                  strArr.push("A、"+response.data.markQuestions[i].optionA)
                }
                if (response.data.markQuestions[i].optionB == '' || response.data.markQuestions[i].optionB == null) {
                } else {
                  strArr.push("B、"+response.data.markQuestions[i].optionB)
                }
                if (response.data.markQuestions[i].optionC == '' || response.data.markQuestions[i].optionC == null) {
                } else {
                  strArr.push("C、"+response.data.markQuestions[i].optionC)
                }
                if (response.data.markQuestions[i].optionD == '' || response.data.markQuestions[i].optionD == null) {
                } else {
                  strArr.push("D、"+response.data.markQuestions[i].optionD)
                }
                if (response.data.markQuestions[i].optionE == '' || response.data.markQuestions[i].optionE == null) {
                } else {
                  strArr.push("E、"+response.data.markQuestions[i].optionE)
                }

                this.checkRadio.push({
                  content: response.data.markQuestions[i].content,//题名
            correctAnswer: response.data.markQuestions[i].correctAnswer,//正确答案
                  id: response.data.markQuestions[i].id,//题目id
                  option: strArr,//题选项
                  questionType: response.data.markQuestions[i].questionType,//题型
                  userAnswer: response.data.markQuestions[i].userAnswers,//用户答案
                })
              }
//              渲染标记判断题
              if (response.data.markQuestions[i].type == 3) {
                var strArr = [];
                if (response.data.markQuestions[i].optionA == '' || response.data.markQuestions[i].optionA == null) {
                } else {
                  strArr.push("A、"+response.data.markQuestions[i].optionA)
                }
                if (response.data.markQuestions[i].optionB == '' || response.data.markQuestions[i].optionB == null) {
                } else {
                  strArr.push("B、"+response.data.markQuestions[i].optionB)
                }
                if (response.data.markQuestions[i].optionC == '' || response.data.markQuestions[i].optionC == null) {
                } else {
                  strArr.push("C、"+response.data.markQuestions[i].optionC)
                }
                if (response.data.markQuestions[i].optionD == '' || response.data.markQuestions[i].optionD == null) {
                } else {
                  strArr.push("D、"+response.data.markQuestions[i].optionD)
                }
                if (response.data.markQuestions[i].optionE == '' || response.data.markQuestions[i].optionE == null) {
                } else {
                  strArr.push("E、"+response.data.markQuestions[i].optionE)
                }

                this.judgeRadio.push({
                  content: response.data.markQuestions[i].content,//题名
            correctAnswer: response.data.markQuestions[i].correctAnswer,//正确答案
                  id: response.data.markQuestions[i].id,//题目id
                  option: strArr,//题选项
                  questionType: response.data.markQuestions[i].questionType,//题型
                  userAnswer: response.data.markQuestions[i].userAnswers,//用户答案
                })
              }
              if (response.data.markQuestions[i].type == 5){
                this.fillRadio.push({
                  content: response.data.markQuestions[i].content,//题名
                  correctAnswer: response.data.markQuestions[i].correctAnswer,//正确答案
                  id: response.data.markQuestions[i].id,//题目id
                  questionType: response.data.markQuestions[i].questionType,//题型
                  userAnswer: response.data.markQuestions[i].userAnswers,//用户答案
                })
              }

            }

        }).catch((error) => {
          console.log("调取失败500");
          this.$Message.error('提交失败！')
        });
      }
    },
    mounted:function() {
      this.ajjax();
      this.getExamCard();
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

  .result{
    width: 1080px;
    margin: auto;
    text-align: center;
    font-size: 15px;
    color: #3B50A1;
    padding-top: 51px;
    padding-bottom: 50px;
  }
  .large{
    font-size: 72px;
  }
  .again{
    display: inline-block;
    margin: auto;
    line-height: 36px;
    text-align: center;
    width:110px;
    height:36px;
    background:rgba(255,255,255,1);
    border:1px solid rgba(59,80,161,1);
    border-radius:20px;
    margin-top: 22px;
    cursor: pointer;
    color: #3B50A1;
  }
  .box{
    width: 14px;
    display: inline-block;
    height: 36px;
  }
  .again:hover{
    background: #3B50A1;
    color: white;
  }
  .tag{
    width: 100%;
    height:43px;
    background:rgba(255,255,255,1);
    box-shadow:0px 0px 11px 0px rgba(4,0,0,0.1);
  }
  .tag_zhong{
    width: 765px;
    margin: auto;
  }
  .tag_zhong div{
    width:85px;
    height: 100%;
    line-height: 43px;
    text-align: center;
    cursor: pointer;
    display: inline-block;
  }
  .click{
    background: #3B50A1;
    color: white;
  }
  .answer_three{
    width: 765px;
    margin: auto;
    background:rgba(255,255,255,1);
    box-shadow:0px 0px 11px 0px rgba(4,0,0,0.1);
    border-radius:1px;
    padding: 13px;
    margin-top: 18px;
  }
  .answer_three_header{
    width: 100%;
    height: 50px;
    border-bottom: 1px solid #BDBDBD;
    position: relative;
    font-size:13px;
    line-height: 50px;
    color:rgba(51,51,51,1);
  }
  .answer_three_header span{
    color: #999999;
  }
  .zi_lan{
    color: #3B50A1;
    font-size: 16px;
  }
  .answer_three_tips{
    color: #999999;
    margin: 14px 0 31px 0;
  }
  .subject{
    line-height: 21px;
    font-size: 12px;
    margin-bottom: 10px;
  }
  .tkj{
    padding-bottom: 10px;
    margin-bottom: 10px;
    border-bottom: 1px  dashed  #E7E7E7;
  }
  ul li{
    list-style: none;
    line-height:40px;
    cursor: pointer;
    font-size: 16px;
  }
  .content{
    /*padding-top: 100px;*/
  }
  .tag{
    z-index: 1;
    margin-top: 20px;
    width: 100%;
    height:60px;
    background:rgba(255,255,255,1);
    box-shadow:0px 0px 11px 0px rgba(4,0,0,0.1);
  }
  .tag_zhong{
    width: 1079px;
    margin: auto;
  }
  .tag_zhong div{
    width:120px;
    height: 100%;
    line-height: 60px;
    text-align: center;
    cursor: pointer;
    display: inline-block;
  }

  .answer_three{
    width: 1079px;
    margin: auto;
    background:rgba(255,255,255,1);
    box-shadow:0px 0px 11px 0px rgba(4,0,0,0.1);
    border-radius:1px;
    padding: 18px;
    margin-top: 26px;
  }
  .answer_three_header{
    width: 100%;
    height: 70px;
    border-bottom: 1px solid #BDBDBD;
    position: relative;
    font-size:18px;
    line-height: 70px;
    color:rgba(51,51,51,1);
  }
  .answer_three_header span{
    color: #999999;
  }
  .zi_lan{
    color: #3B50A1;
  }
  .answer_three_tips{
    color: #999999;
    margin: 30px 0 35px 0;
  }
  .subject{
    line-height:30px;
    font-size: 16px;
    margin-bottom: 24px;
  }
  .tkj{
    padding-bottom: 20px;
    margin-bottom: 20px;
    border-bottom: 2px  dashed  #E7E7E7;
    position: relative;
  }

</style>
